home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / content / nsIDocument.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  30KB  |  905 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsIDocument_h___
  38. #define nsIDocument_h___
  39.  
  40. #include "nsISupports.h"
  41. #include "nsEvent.h"
  42. #include "nsString.h"
  43. #include "nsCOMArray.h"
  44. #include "nsIDocumentObserver.h"
  45. #include "nsCOMPtr.h"
  46. #include "nsIURI.h"
  47. #include "nsIBindingManager.h"
  48. #include "nsWeakPtr.h"
  49. #include "nsIWeakReferenceUtils.h"
  50. #include "nsILoadGroup.h"
  51. #include "nsReadableUtils.h"
  52. #include "nsCRT.h"
  53. #include "mozFlushType.h"
  54. #include "nsPropertyTable.h"
  55. #include "nsHashSets.h"
  56. #include "nsAutoPtr.h"
  57.  
  58. class nsIAtom;
  59. class nsIContent;
  60. class nsPresContext;
  61. class nsIPresShell;
  62.  
  63. class nsIStreamListener;
  64. class nsIStreamObserver;
  65. class nsStyleSet;
  66. class nsIStyleSheet;
  67. class nsIStyleRule;
  68. class nsIViewManager;
  69. class nsIScriptGlobalObject;
  70. class nsPIDOMWindow;
  71. class nsIDOMEvent;
  72. class nsIDeviceContext;
  73. class nsIParser;
  74. class nsIDOMNode;
  75. class nsIDOMDocumentFragment;
  76. class nsILineBreaker;
  77. class nsIWordBreaker;
  78. class nsISelection;
  79. class nsIChannel;
  80. class nsIPrincipal;
  81. class nsIDOMDocument;
  82. class nsIDOMDocumentType;
  83. class nsIObserver;
  84. class nsISupportsArray;
  85. class nsIScriptLoader;
  86. class nsIContentSink;
  87. class nsIScriptEventManager;
  88. class nsNodeInfoManager;
  89. class nsICSSLoader;
  90. class nsHTMLStyleSheet;
  91. class nsIHTMLCSSStyleSheet;
  92. class nsILayoutHistoryState;
  93.  
  94. // IID for the nsIDocument interface
  95. #define NS_IDOCUMENT_IID      \
  96. { 0xd7c47f55, 0x480b, 0x4a60, \
  97.   { 0x9a, 0xdf, 0xca, 0x49, 0x87, 0x3c, 0x71, 0xe2 } }
  98.  
  99. // The base value for the content ID counter.
  100. // This counter is used by the document to 
  101. // assign a monotonically increasing ID to each content
  102. // object it creates
  103. #define NS_CONTENT_ID_COUNTER_BASE 10000
  104.  
  105.  
  106. // Flag for AddStyleSheet().
  107. #define NS_STYLESHEET_FROM_CATALOG                (1 << 0)
  108.  
  109. //----------------------------------------------------------------------
  110.  
  111. // Document interface
  112. class nsIDocument : public nsISupports
  113. {
  114. public:
  115.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
  116.   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
  117.  
  118.   nsIDocument()
  119.     : mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
  120.       mNextContentID(NS_CONTENT_ID_COUNTER_BASE),
  121.       mNodeInfoManager(nsnull),
  122.       mPartID(0)
  123.   {
  124.   }
  125.  
  126.   virtual nsresult StartDocumentLoad(const char* aCommand,
  127.                                      nsIChannel* aChannel,
  128.                                      nsILoadGroup* aLoadGroup,
  129.                                      nsISupports* aContainer,
  130.                                      nsIStreamListener **aDocListener,
  131.                                      PRBool aReset,
  132.                                      nsIContentSink* aSink = nsnull) = 0;
  133.  
  134.   virtual void StopDocumentLoad() = 0;
  135.  
  136.   /**
  137.    * Return the title of the document. May return null.
  138.    */
  139.   const nsAFlatString& GetDocumentTitle() const
  140.   {
  141.     return mDocumentTitle;
  142.   }
  143.  
  144.   /**
  145.    * Return the URI for the document. May return null.
  146.    */
  147.   nsIURI* GetDocumentURI() const
  148.   {
  149.     return mDocumentURI;
  150.   }
  151.   void SetDocumentURI(nsIURI* aURI)
  152.   {
  153.     mDocumentURI = aURI;
  154.   }
  155.  
  156.   /**
  157.    * Return the principal responsible for this document.
  158.    */
  159.   virtual nsIPrincipal* GetPrincipal() = 0;
  160.  
  161.   /**
  162.    * Set the principal responsible for this document.
  163.    */
  164.   virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
  165.  
  166.   /**
  167.    * Return the LoadGroup for the document. May return null.
  168.    */
  169.   already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
  170.   {
  171.     nsILoadGroup *group = nsnull;
  172.     if (mDocumentLoadGroup)
  173.       CallQueryReferent(mDocumentLoadGroup.get(), &group);
  174.  
  175.     return group;
  176.   }
  177.  
  178.   /**
  179.    * Return the base URI for relative URIs in the document (the document uri
  180.    * unless it's overridden by SetBaseURI, HTML <base> tags, etc.).  The
  181.    * returned URI could be null if there is no document URI.
  182.    */
  183.   nsIURI* GetBaseURI() const
  184.   {
  185.     return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
  186.   }
  187.   virtual nsresult SetBaseURI(nsIURI* aURI) = 0;
  188.  
  189.   /**
  190.    * Get/Set the base target of a link in a document.
  191.    */
  192.   virtual void GetBaseTarget(nsAString &aBaseTarget) const = 0;
  193.   virtual void SetBaseTarget(const nsAString &aBaseTarget) = 0;
  194.  
  195.   /**
  196.    * Return a standard name for the document's character set. This
  197.    * will trigger a startDocumentLoad if necessary to answer the
  198.    * question.
  199.    */
  200.   const nsAFlatCString& GetDocumentCharacterSet() const
  201.   {
  202.     return mCharacterSet;
  203.   }
  204.  
  205.   /**
  206.    * Set the document's character encoding. |aCharSetID| should be canonical. 
  207.    * That is, callers are responsible for the charset alias resolution. 
  208.    */
  209.   virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) = 0;
  210.  
  211.   PRInt32 GetDocumentCharacterSetSource() const
  212.   {
  213.     return mCharacterSetSource;
  214.   }
  215.  
  216.   void SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
  217.   {
  218.     mCharacterSetSource = aCharsetSource;
  219.   }
  220.  
  221.   /**
  222.    * Add an observer that gets notified whenever the charset changes.
  223.    */
  224.   virtual nsresult AddCharSetObserver(nsIObserver* aObserver) = 0;
  225.  
  226.   /**
  227.    * Remove a charset observer.
  228.    */
  229.   virtual void RemoveCharSetObserver(nsIObserver* aObserver) = 0;
  230.  
  231.   /**
  232.    * Get the Content-Type of this document.
  233.    * (This will always return NS_OK, but has this signature to be compatible
  234.    *  with nsIDOMNSDocument::GetContentType())
  235.    */
  236.   NS_IMETHOD GetContentType(nsAString& aContentType) = 0;
  237.  
  238.   /**
  239.    * Set the Content-Type of this document.
  240.    */
  241.   virtual void SetContentType(const nsAString& aContentType) = 0;
  242.  
  243.   /**
  244.    * Return the language of this document.
  245.    */
  246.   void GetContentLanguage(nsAString& aContentLanguage) const
  247.   {
  248.     CopyASCIItoUCS2(mContentLanguage, aContentLanguage);
  249.   }
  250.  
  251.   // The state BidiEnabled should persist across multiple views
  252.   // (screen, print) of the same document.
  253.  
  254.   /**
  255.    * Check if the document contains bidi data.
  256.    * If so, we have to apply the Unicode Bidi Algorithm.
  257.    */
  258.   PRBool GetBidiEnabled() const
  259.   {
  260.     return mBidiEnabled;
  261.   }
  262.  
  263.   /**
  264.    * Indicate the document contains bidi data.
  265.    * Currently, we cannot disable bidi, because once bidi is enabled,
  266.    * it affects a frame model irreversibly, and plays even though
  267.    * the document no longer contains bidi data.
  268.    */
  269.   void SetBidiEnabled(PRBool aBidiEnabled)
  270.   {
  271.     mBidiEnabled = aBidiEnabled;
  272.   }
  273.  
  274.   /**
  275.    * Return the Line Breaker for the document
  276.    */
  277.   virtual nsILineBreaker* GetLineBreaker() = 0;
  278.   virtual void SetLineBreaker(nsILineBreaker* aLineBreaker) = 0;
  279.   virtual nsIWordBreaker* GetWordBreaker() = 0;
  280.   virtual void SetWordBreaker(nsIWordBreaker* aWordBreaker) = 0;
  281.  
  282.   /**
  283.    * Access HTTP header data (this may also get set from other
  284.    * sources, like HTML META tags).
  285.    */
  286.   virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
  287.   virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
  288.  
  289.   /**
  290.    * Create a new presentation shell that will use aContext for its
  291.    * presentation context (presentation contexts <b>must not</b> be
  292.    * shared among multiple presentation shells).
  293.    */
  294.   virtual nsresult CreateShell(nsPresContext* aContext,
  295.                                nsIViewManager* aViewManager,
  296.                                nsStyleSet* aStyleSet,
  297.                                nsIPresShell** aInstancePtrResult) = 0;
  298.   virtual PRBool DeleteShell(nsIPresShell* aShell) = 0;
  299.   virtual PRUint32 GetNumberOfShells() const = 0;
  300.   virtual nsIPresShell *GetShellAt(PRUint32 aIndex) const = 0;
  301.  
  302.   /**
  303.    * Return the parent document of this document. Will return null
  304.    * unless this document is within a compound document and has a
  305.    * parent. Note that this parent chain may cross chrome boundaries.
  306.    */
  307.   nsIDocument *GetParentDocument() const
  308.   {
  309.     return mParentDocument;
  310.   }
  311.  
  312.   /**
  313.    * Set the parent document of this document.
  314.    */
  315.   void SetParentDocument(nsIDocument* aParent)
  316.   {
  317.     mParentDocument = aParent;
  318.   }
  319.  
  320.   /**
  321.    * Set the sub document for aContent to aSubDoc.
  322.    */
  323.   virtual nsresult SetSubDocumentFor(nsIContent *aContent,
  324.                                      nsIDocument* aSubDoc) = 0;
  325.  
  326.   /**
  327.    * Get the sub document for aContent
  328.    */
  329.   virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
  330.  
  331.   /**
  332.    * Find the content node for which aDocument is a sub document.
  333.    */
  334.   virtual nsIContent *FindContentForSubDocument(nsIDocument *aDocument) const = 0;
  335.  
  336.   /**
  337.    * Return the root content object for this document.
  338.    */
  339.   nsIContent *GetRootContent() const
  340.   {
  341.     return mRootContent;
  342.   }
  343.  
  344.   /**
  345.    * Set aRoot as the root content object for this document.  If aRoot is
  346.    * non-null, this should not be called on documents that currently have a
  347.    * root content without first clearing out the document's children.  Passing
  348.    * in null to unbind the existing root content is allowed.  This method will
  349.    * bind aRoot to the document; the caller need not call BindToTree on aRoot.
  350.    *
  351.    * Note that this method never sends out nsIDocumentObserver notifications;
  352.    * doing that is the caller's responsibility.
  353.    */
  354.   virtual nsresult SetRootContent(nsIContent* aRoot) = 0;
  355.  
  356.   /** 
  357.    * Get the direct children of the document - content in
  358.    * the prolog, the root content and content in the epilog.
  359.    */
  360.   virtual nsIContent *GetChildAt(PRUint32 aIndex) const = 0;
  361.   virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const = 0;
  362.   virtual PRUint32 GetChildCount() const = 0;
  363.  
  364.   /**
  365.    * Accessors to the collection of stylesheets owned by this document.
  366.    * Style sheets are ordered, most significant last.
  367.    */
  368.  
  369.   /**
  370.    * Get the number of stylesheets
  371.    *
  372.    * @return the number of stylesheets
  373.    * @throws no exceptions
  374.    */
  375.   virtual PRInt32 GetNumberOfStyleSheets() const = 0;
  376.   
  377.   /**
  378.    * Get a particular stylesheet
  379.    * @param aIndex the index the stylesheet lives at.  This is zero-based
  380.    * @return the stylesheet at aIndex.  Null if aIndex is out of range.
  381.    * @throws no exceptions
  382.    */
  383.   virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) const = 0;
  384.   
  385.   /**
  386.    * Insert a sheet at a particular spot in the stylesheet list (zero-based)
  387.    * @param aSheet the sheet to insert
  388.    * @param aIndex the index to insert at.  This index will be
  389.    *   adjusted for the "special" sheets.
  390.    * @throws no exceptions
  391.    */
  392.   virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) = 0;
  393.  
  394.   /**
  395.    * Get the index of a particular stylesheet.  This will _always_
  396.    * consider the "special" sheets as part of the sheet list.
  397.    * @param aSheet the sheet to get the index of
  398.    * @return aIndex the index of the sheet in the full list
  399.    */
  400.   virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0;
  401.  
  402.   /**
  403.    * Replace the stylesheets in aOldSheets with the stylesheets in
  404.    * aNewSheets. The two lists must have equal length, and the sheet
  405.    * at positon J in the first list will be replaced by the sheet at
  406.    * position J in the second list.  Some sheets in the second list
  407.    * may be null; if so the corresponding sheets in the first list
  408.    * will simply be removed.
  409.    */
  410.   virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
  411.                                  nsCOMArray<nsIStyleSheet>& aNewSheets) = 0;
  412.  
  413.   /**
  414.    * Add a stylesheet to the document
  415.    */
  416.   virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
  417.  
  418.   /**
  419.    * Remove a stylesheet from the document
  420.    */
  421.   virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
  422.  
  423.   /**
  424.    * Notify the document that the applicable state of the sheet changed
  425.    * and that observers should be notified and style sets updated
  426.    */
  427.   virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
  428.                                             PRBool aApplicable) = 0;  
  429.  
  430.   /**
  431.    * Just like the style sheet API, but for "catalog" sheets,
  432.    * extra sheets inserted at the UA level.
  433.    */
  434.   virtual PRInt32 GetNumberOfCatalogStyleSheets() const = 0;
  435.   virtual nsIStyleSheet* GetCatalogStyleSheetAt(PRInt32 aIndex) const = 0;
  436.   virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet) = 0;
  437.   virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI) = 0;
  438.  
  439.   /**
  440.    * Get this document's CSSLoader.  This is guaranteed to not return null.
  441.    */
  442.   nsICSSLoader* CSSLoader() const {
  443.     return mCSSLoader;
  444.   }
  445.  
  446.   /**
  447.    * Get the channel that was passed to StartDocumentLoad or Reset for this
  448.    * document.  Note that this may be null in some cases (eg if
  449.    * StartDocumentLoad or Reset were never called)
  450.    */
  451.   virtual nsIChannel* GetChannel() const = 0;
  452.  
  453.   /**
  454.    * Get this document's attribute stylesheet.  May return null if
  455.    * there isn't one.
  456.    */
  457.   virtual nsHTMLStyleSheet* GetAttributeStyleSheet() const = 0;
  458.  
  459.   /**
  460.    * Get this document's inline style sheet.  May return null if there
  461.    * isn't one
  462.    */
  463.   virtual nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const = 0;
  464.   
  465.   /**
  466.    * Get/set the object from which a document can get a script context
  467.    * and scope. This is the context within which all scripts (during
  468.    * document creation and during event handling) will run. Note that
  469.    * this is the *inner* window object.
  470.    */
  471.   virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0;
  472.   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
  473.  
  474.   /**
  475.    * Return the window containing the document (the outer window).
  476.    */
  477.   virtual nsPIDOMWindow *GetWindow() = 0;
  478.  
  479.   /**
  480.    * Get the script loader for this document
  481.    */ 
  482.   virtual nsIScriptLoader* GetScriptLoader() = 0;
  483.  
  484.   //----------------------------------------------------------------------
  485.  
  486.   // Document notification API's
  487.  
  488.   /**
  489.    * Add a new observer of document change notifications. Whenever
  490.    * content is changed, appended, inserted or removed the observers are
  491.    * informed.
  492.    */
  493.   virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
  494.  
  495.   /**
  496.    * Remove an observer of document change notifications. This will
  497.    * return false if the observer cannot be found.
  498.    */
  499.   virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
  500.  
  501.   // Observation hooks used to propagate notifications to document observers.
  502.   // BeginUpdate must be called before any batch of modifications of the
  503.   // content model or of style data, EndUpdate must be called afterward.
  504.   // To make this easy and painless, use the mozAutoDocUpdate helper class.
  505.   virtual void BeginUpdate(nsUpdateType aUpdateType) = 0;
  506.   virtual void EndUpdate(nsUpdateType aUpdateType) = 0;
  507.   virtual void BeginLoad() = 0;
  508.   virtual void EndLoad() = 0;
  509.   virtual void CharacterDataChanged(nsIContent* aContent, PRBool aAppend) = 0;
  510.   // notify that one or two content nodes changed state
  511.   // either may be nsnull, but not both
  512.   virtual void ContentStatesChanged(nsIContent* aContent1,
  513.                                     nsIContent* aContent2,
  514.                                     PRInt32 aStateMask) = 0;
  515.   virtual void AttributeWillChange(nsIContent* aChild,
  516.                                    PRInt32 aNameSpaceID,
  517.                                    nsIAtom* aAttribute) = 0;
  518.   virtual void AttributeChanged(nsIContent* aChild,
  519.                                 PRInt32 aNameSpaceID,
  520.                                 nsIAtom* aAttribute,
  521.                                 PRInt32 aModType) = 0;
  522.   virtual void ContentAppended(nsIContent* aContainer,
  523.                                PRInt32 aNewIndexInContainer) = 0;
  524.   virtual void ContentInserted(nsIContent* aContainer,
  525.                                nsIContent* aChild,
  526.                                PRInt32 aIndexInContainer) = 0;
  527.   virtual void ContentRemoved(nsIContent* aContainer,
  528.                               nsIContent* aChild,
  529.                               PRInt32 aIndexInContainer) = 0;
  530.  
  531.   // Observation hooks for style data to propagate notifications
  532.   // to document observers
  533.   virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
  534.                                 nsIStyleRule* aOldStyleRule,
  535.                                 nsIStyleRule* aNewStyleRule) = 0;
  536.   virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
  537.                               nsIStyleRule* aStyleRule) = 0;
  538.   virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
  539.                                 nsIStyleRule* aStyleRule) = 0;
  540.  
  541.   virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
  542.                                   nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
  543.                                   PRUint32 aFlags,
  544.                                   nsEventStatus* aEventStatus) = 0;
  545.  
  546.   /**
  547.    * Flush notifications for this document and its parent documents
  548.    * (since those may affect the layout of this one).
  549.    */
  550.   virtual void FlushPendingNotifications(mozFlushType aType) = 0;
  551.  
  552.   PRInt32 GetAndIncrementContentID()
  553.   {
  554.     return mNextContentID++;
  555.   }
  556.  
  557.   nsIBindingManager* BindingManager() const
  558.   {
  559.     return mBindingManager;
  560.   }
  561.  
  562.   /**
  563.    * Only to be used inside Gecko, you can't really do anything with the
  564.    * pointer outside Gecko anyway.
  565.    */
  566.   nsNodeInfoManager* NodeInfoManager() const
  567.   {
  568.     return mNodeInfoManager;
  569.   }
  570.  
  571.   /**
  572.    * Reset the document using the given channel and loadgroup.  This works
  573.    * like ResetToURI, but also sets the document's channel to aChannel.
  574.    */
  575.   virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
  576.  
  577.   /**
  578.    * Reset this document to aURI and aLoadGroup.  aURI must not be null.
  579.    */
  580.   virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup) = 0;
  581.  
  582.   /**
  583.    * Set the container (docshell) for this document.
  584.    */
  585.   void SetContainer(nsISupports *aContainer)
  586.   {
  587.     mDocumentContainer = do_GetWeakReference(aContainer);
  588.   }
  589.  
  590.   /**
  591.    * Get the container (docshell) for this document.
  592.    */
  593.   already_AddRefed<nsISupports> GetContainer() const
  594.   {
  595.     nsISupports* container = nsnull;
  596.     if (mDocumentContainer)
  597.       CallQueryReferent(mDocumentContainer.get(), &container);
  598.  
  599.     return container;
  600.   }
  601.  
  602.   virtual nsIScriptEventManager* GetScriptEventManager() = 0;
  603.  
  604.   /**
  605.    * Set and get XML declaration. If aVersion is null there is no declaration.
  606.    * aStandalone takes values -1, 0 and 1 indicating respectively that there
  607.    * was no standalone parameter in the declaration, that it was given as no,
  608.    * or that it was given as yes.
  609.    */
  610.   virtual void SetXMLDeclaration(const PRUnichar *aVersion,
  611.                                  const PRUnichar *aEncoding,
  612.                                  const PRInt32 aStandalone) = 0;
  613.   virtual void GetXMLDeclaration(nsAString& aVersion,
  614.                                  nsAString& aEncoding,
  615.                                  nsAString& Standalone) = 0;
  616.  
  617.   virtual PRBool IsCaseSensitive()
  618.   {
  619.     return PR_TRUE;
  620.   }
  621.  
  622.   virtual PRBool IsScriptEnabled() = 0;
  623.  
  624.   virtual nsresult AddXMLEventsContent(nsIContent * aXMLEventsElement) = 0;
  625.  
  626.   virtual PRBool IsLoadedAsData()
  627.   {
  628.     return PR_FALSE;
  629.   }
  630.  
  631.   /**
  632.    * Create an element with the specified name, prefix and namespace ID.
  633.    * If aDocumentDefaultType is true we create an element of the default type
  634.    * for that document (currently XHTML in HTML documents and XUL in XUL
  635.    * documents), otherwise we use the type specified by the namespace ID.
  636.    */
  637.   virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
  638.                               PRInt32 aNamespaceID,
  639.                               PRBool aDocumentDefaultType,
  640.                               nsIContent** aResult) = 0;
  641.  
  642.   /**
  643.    * Get the security info (i.e. SSL state etc) that the document got
  644.    * from the channel/document that created the content of the
  645.    * document.
  646.    *
  647.    * @see nsIChannel
  648.    */
  649.   nsISupports *GetSecurityInfo()
  650.   {
  651.     return mSecurityInfo;
  652.   }
  653.  
  654.   /**
  655.    * Returns the default namespace ID used for elements created in this
  656.    * document.
  657.    */
  658.   virtual PRInt32 GetDefaultNamespaceID() const = 0;
  659.  
  660.   virtual void* GetProperty(nsIAtom *aPropertyName,
  661.                             nsresult *aStatus = nsnull) const = 0;
  662.  
  663.   virtual nsresult SetProperty(nsIAtom            *aPropertyName,
  664.                                void               *aValue,
  665.                                NSPropertyDtorFunc  aDtor = nsnull) = 0;
  666.  
  667.   virtual nsresult DeleteProperty(nsIAtom *aPropertyName) = 0;
  668.  
  669.   virtual void* UnsetProperty(nsIAtom  *aPropertyName,
  670.                               nsresult *aStatus = nsnull) = 0;
  671.  
  672.   nsPropertyTable* PropertyTable() { return &mPropertyTable; }
  673.  
  674.   /**
  675.    * Sets the ID used to identify this part of the multipart document
  676.    */
  677.   void SetPartID(PRUint32 aID) {
  678.     mPartID = aID;
  679.   }
  680.  
  681.   /**
  682.    * Return the ID used to identify this part of the multipart document
  683.    */
  684.   PRUint32 GetPartID() const {
  685.     return mPartID;
  686.   }
  687.  
  688.   /**
  689.    * Sanitize the document by resetting all input elements and forms that have
  690.    * autocomplete=off to their default values.
  691.    */
  692.   virtual nsresult Sanitize() = 0;
  693.  
  694.   /**
  695.    * Enumerate all subdocuments.
  696.    * The enumerator callback should return PR_TRUE to continue enumerating, or
  697.    * PR_FALSE to stop.
  698.    */
  699.   typedef PRBool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
  700.   virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
  701.                                      void *aData) = 0;
  702.  
  703.   /**
  704.    * Check whether it is safe to cache the presentation of this document
  705.    * and all of its subdocuments. This method checks the following conditions
  706.    * recursively:
  707.    *  - Some document types, such as plugin documents, cannot be safely cached.
  708.    *  - If there are any pending requests, we don't allow the presentation
  709.    *    to be cached.  Ideally these requests would be suspended and resumed,
  710.    *    but that is difficult in some cases, such as XMLHttpRequest.
  711.    *  - If there are any beforeunload or unload listeners, we must fire them
  712.    *    for correctness, but this likely puts the document into a state where
  713.    *    it would not function correctly if restored.
  714.    *
  715.    * |aNewRequest| should be the request for a new document which will
  716.    * replace this document in the docshell.  The new document's request
  717.    * will be ignored when checking for active requests.  If there is no
  718.    * request associated with the new document, this parameter may be null.
  719.    */
  720.   virtual PRBool CanSavePresentation(nsIRequest *aNewRequest) = 0;
  721.  
  722.   /**
  723.    * Notify the document that its associated ContentViewer is being destroyed.
  724.    * This releases circular references so that the document can go away.
  725.    * Destroy() is only called on documents that have a content viewer.
  726.    */
  727.   virtual void Destroy() = 0;
  728.  
  729.   /**
  730.    * Get the layout history state that should be used to save and restore state
  731.    * for nodes in this document.  This may return null; if that happens state
  732.    * saving and restoration is not possible.
  733.    */
  734.   virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const = 0;
  735.  
  736.   /**
  737.    * Methods that can be used to prevent onload firing while an event that
  738.    * should block onload is posted.  onload is guaranteed to not fire until
  739.    * either all calls to BlockOnload() have been matched by calls to
  740.    * UnblockOnload() or the load has been stopped altogether (by the user
  741.    * pressing the Stop button, say).  onload may fire synchronously from inside
  742.    * the UnblockOnload() call.
  743.    */
  744.   virtual void BlockOnload() = 0;
  745.   virtual void UnblockOnload() = 0;
  746.  
  747.   /**
  748.    * Notification that the page has been shown, for documents which are loaded
  749.    * into a DOM window.  This corresponds to the completion of document load,
  750.    * or to the page's presentation being restored into an existing DOM window.
  751.    * This notification fires applicable DOM events to the content window.  See
  752.    * nsIDOMPageTransitionEvent.idl for a description of the |aPersisted|
  753.    * parameter.
  754.    */
  755.   virtual void OnPageShow(PRBool aPersisted) = 0;
  756.  
  757.   /**
  758.    * Notification that the page has been hidden, for documents which are loaded
  759.    * into a DOM window.  This corresponds to the unloading of the document, or
  760.    * to the document's presentation being saved but removed from an existing
  761.    * DOM window.  This notification fires applicable DOM events to the content
  762.    * window.  See nsIDOMPageTransitionEvent.idl for a description of the
  763.    * |aPersisted| parameter.
  764.    */
  765.   virtual void OnPageHide(PRBool aPersisted) = 0;
  766.   
  767.   /*
  768.    * We record the set of links in the document that are relevant to
  769.    * style.
  770.    */
  771.   /**
  772.    * Notification that an element is a link with a given URI that is
  773.    * relevant to style.
  774.    */
  775.   virtual void AddStyleRelevantLink(nsIContent* aContent, nsIURI* aURI) = 0;
  776.   /**
  777.    * Notification that an element is a link and its URI might have been
  778.    * changed or the element removed. If the element is still a link relevant
  779.    * to style, then someone must ensure that AddStyleRelevantLink is
  780.    * (eventually) called on it again.
  781.    */
  782.   virtual void ForgetLink(nsIContent* aContent) = 0;
  783.   /**
  784.    * Notification that the visitedness state of a URI has been changed
  785.    * and style related to elements linking to that URI should be updated.
  786.    */
  787.   virtual void NotifyURIVisitednessChanged(nsIURI* aURI) = 0;
  788.  
  789. protected:
  790.   ~nsIDocument()
  791.   {
  792.     // XXX The cleanup of mNodeInfoManager (calling DropDocumentReference and
  793.     //     releasing it) happens in the nsDocument destructor. We'd prefer to
  794.     //     do it here but nsNodeInfoManager is a concrete class that we don't
  795.     //     want to expose to users of the nsIDocument API outside of Gecko.
  796.   }
  797.  
  798.   nsString mDocumentTitle;
  799.   nsCOMPtr<nsIURI> mDocumentURI;
  800.   nsCOMPtr<nsIURI> mDocumentBaseURI;
  801.  
  802.   nsWeakPtr mDocumentLoadGroup;
  803.  
  804.   nsWeakPtr mDocumentContainer;
  805.  
  806.   nsCString mCharacterSet;
  807.   PRInt32 mCharacterSetSource;
  808.  
  809.   // This is just a weak pointer; the parent document owns its children.
  810.   nsIDocument* mParentDocument;
  811.  
  812.   // A weak reference to the only child element, or null if no
  813.   // such element exists.
  814.   nsIContent* mRootContent;
  815.  
  816.   // A content ID counter used to give a monotonically increasing ID
  817.   // to the content objects in the document's content model
  818.   PRInt32 mNextContentID;
  819.  
  820.   nsCOMPtr<nsIBindingManager> mBindingManager;
  821.   nsNodeInfoManager* mNodeInfoManager; // [STRONG]
  822.  
  823.   nsICSSLoader* mCSSLoader; // [STRONG; not a COMPtr to avoid
  824.                             // including nsICSSLoader.h; the ownership
  825.                             // is managed by nsDocument]
  826.  
  827.   // Table of element properties for this document.
  828.   nsPropertyTable mPropertyTable;
  829.  
  830.   // True if BIDI is enabled.
  831.   PRBool mBidiEnabled;
  832.  
  833.   nsXPIDLCString mContentLanguage;
  834.   nsCString mContentType;
  835.  
  836.   // The document's security info
  837.   nsCOMPtr<nsISupports> mSecurityInfo;
  838.  
  839.   // if this document is part of a multipart document,
  840.   // the ID can be used to distinguish it from the other parts.
  841.   PRUint32 mPartID;
  842. };
  843.  
  844.  
  845. /**
  846.  * Helper class to automatically handle batching of document updates.  This
  847.  * class will call BeginUpdate on construction and EndUpdate on destruction on
  848.  * the given document with the given update type.  The document could be null,
  849.  * in which case no updates will be called.  The constructor also takes a
  850.  * boolean that can be set to false to prevent notifications.
  851.  */
  852. class mozAutoDocUpdate
  853. {
  854. public:
  855.   mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
  856.                    PRBool aNotify) :
  857.     mDocument(aNotify ? aDocument : nsnull),
  858.     mUpdateType(aUpdateType)
  859.   {
  860.     if (mDocument) {
  861.       mDocument->BeginUpdate(mUpdateType);
  862.     }
  863.   }
  864.  
  865.   ~mozAutoDocUpdate()
  866.   {
  867.     if (mDocument) {
  868.       mDocument->EndUpdate(mUpdateType);
  869.     }
  870.   }
  871.  
  872. private:
  873.   nsCOMPtr<nsIDocument> mDocument;
  874.   nsUpdateType mUpdateType;
  875. };
  876.  
  877. // XXX These belong somewhere else
  878. nsresult
  879. NS_NewHTMLDocument(nsIDocument** aInstancePtrResult);
  880.  
  881. nsresult
  882. NS_NewXMLDocument(nsIDocument** aInstancePtrResult);
  883.  
  884. #ifdef MOZ_SVG
  885. nsresult
  886. NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
  887. #endif
  888.  
  889. nsresult
  890. NS_NewImageDocument(nsIDocument** aInstancePtrResult);
  891.  
  892. nsresult
  893. NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
  894.                        nsIDocument* aOwnerDocument);
  895. nsresult
  896. NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
  897.                   const nsAString& aNamespaceURI, 
  898.                   const nsAString& aQualifiedName, 
  899.                   nsIDOMDocumentType* aDoctype,
  900.                   nsIURI* aBaseURI);
  901. nsresult
  902. NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
  903.  
  904. #endif /* nsIDocument_h___ */
  905.